﻿using Centny.Data;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.Display;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Centny.TestPage;
// 項目頁面項目範本已記錄在 http://go.microsoft.com/fwlink/?LinkId=234233

namespace Centny
{
    /// <summary>
    /// 顯示項目預覽集合之頁面。在分割應用程式中，此頁面
    /// 是用來顯示及選取其中一個可用的群組。
    /// </summary>
    /// 
    public class TemplateSelector : DataTemplateSelector
    {
        public DataTemplate T1 { get; set; }
        public DataTemplate T2 { get; set; }
        public DataTemplate T3 { get; set; }
        public DataTemplate T4 { get; set; }
        public DataTemplate T5 { get; set; }
        public bool IsFirst { get; set; }
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            Random rd = new Random();
            int v = rd.Next(0, 5);
            if (this.IsFirst)
            {
                this.IsFirst = false;
                return this.T1;
            }
            switch (v)
            {
                case 0:
                    return this.T1;
                case 1:
                    return this.T2;
                case 2:
                    return this.T3;
                case 3:
                    return this.T4;
                case 4:
                    return this.T5;
            }
            return null;
        }

    }
    public sealed partial class ItemsPage : Centny.Common.LayoutAwarePage
    {
        public ItemsPage()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// 巡覽期間以傳遞的內容填入頁面。從之前的工作階段
        /// 重新建立頁面時，也會提供儲存的狀態。
        /// </summary>
        /// <param name="navigationParameter">最初要求這個頁面時，傳遞到
        /// <see cref="Frame.Navigate(Type, Object)"/> 的參數。
        /// </param>
        /// <param name="pageState">這個頁面在先前的工作階段期間保留的
        /// 狀態字典。第一次瀏覽頁面時，這一項是 null。</param>
        /// 
        class SObj
        {
            public String Text { get; set; }
            public SObj(String t)
            {
                this.Text = t;
            }
        }
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            // TODO: 為您的問題領域建立適合的資料模型，以取代資料範例
            List<SObj> titles = new List<SObj>();
            titles.Add(new SObj("AutoHor"));
            titles.Add(new SObj("AutoRandom"));
            titles.Add(new SObj("AutoTime"));
            titles.Add(new SObj("AutoWaterfallHor"));
            titles.Add(new SObj("AutoWaterfallVer"));
            titles.Add(new SObj("GroupGridView"));
            titles.Add(new SObj("GroupAutoCanvas"));
            titles.Add(new SObj("Img"));
            titles.Add(new SObj("DT"));
            titles.Add(new SObj("StackPanel"));
            titles.Add(new SObj("ScrollViewer"));
            titles.Add(new SObj("Button"));
            titles.Add(new SObj("Scroll"));
            titles.Add(new SObj("WebView"));
            titles.Add(new SObj("ReadFile"));
            titles.Add(new SObj("Dynamic"));
            titles.Add(new SObj("FlipView"));
            this.DefaultViewModel["Items"] = titles;
        }
        public String Title { get; set; }
        /// <summary>
        /// 按一下項目時叫用。
        /// </summary>
        /// <param name="sender">GridView (或快照應用程式時為 ListView)
        /// 顯示已按下的項目。</param>
        /// <param name="e">描述已按下之項目的事件資料。</param>
        void ItemView_ItemClick(object sender, ItemClickEventArgs e)
        {
            // 巡覽至適用的目的頁面，設定新的頁面
            // 方式是透過傳遞必要資訊做為巡覽參數
            SObj so = e.ClickedItem as SObj;
            if (so.Text.Equals("GroupGridView"))
            {
                this.Frame.Navigate(typeof(GroupedItemsPage));
            }
            else if (so.Text.Equals("GroupAutoCanvas"))
            {
                this.Frame.Navigate(typeof(GAutoCanvasPage));
            }
            else if (so.Text.Equals("Img"))
            {
                this.Frame.Navigate(typeof(ImageTest));
            }
            else if (so.Text.Equals("DT"))
            {
                this.Frame.Navigate(typeof(DTTest));
            }
            else if (so.Text.Equals("StackPanel"))
            {
                this.Frame.Navigate(typeof(StackPanelPage));
            }
            else if (so.Text.Equals("ScrollViewer"))
            {
                this.Frame.Navigate(typeof(ScrollViewerPage));
            }
            else if (so.Text.Equals("Button"))
            {
                this.Frame.Navigate(typeof(ButtonTest));
            }
            else if (so.Text.Equals("Scroll"))
            {
                this.Frame.Navigate(typeof(ScrollPage));
            }
            else if (so.Text.Equals("WebView"))
            {
                this.Frame.Navigate(typeof(ExtWebViewTest));
            }
            else if (so.Text.Equals("ReadFile"))
            {
                this.Frame.Navigate(typeof(TestReadFile));
            }
            else if (so.Text.Equals("Dynamic"))
            {
                this.Frame.Navigate(typeof(DynamicStyle));
            }
            else if (so.Text.Equals("FlipView"))
            {
                this.Frame.Navigate(typeof(TestFlipView));
            }
            else
            {
                this.Frame.Navigate(typeof(SplitPage), so.Text);
            }
            //this.Frame.Navigate(typeof(GroupedItemsPage));
        }

        private void pageTitle_Tapped_1(object sender, TappedRoutedEventArgs e)
        {
            int a = 0;
        }

        private void pageTitle_PointerPressed_1(object sender, PointerRoutedEventArgs e)
        {
            int a = 0;

        }
    }
}
